import { localStorage } from 'src/adapter/localstorage';

import { Store } from 'vuex';
export const init = (store: Store<any>) => {
  const visitor = localStorage.getItem('visitor');
  if (visitor) store.commit('visitor/setVisitor', visitor);

  const profile = localStorage.getItem('PROFILE');
  if (profile) store.commit('login/SET_PROFILE', profile);

  const access_token = localStorage.getItem('ACCESS_TOKEN');

  if (access_token) {
    store.commit('global/SET_LOGIN_DIALOG_VISIBLE', false);
    store.commit('login/SET_ACCESS_TOKEN', access_token);
  }
  const refresh_token = localStorage.getItem('RFRESH_TOKEN');
  if (refresh_token) {
    store.commit('login/SET_RFRESH_TOKEN', refresh_token);
  }
  const commentLikeHistory = localStorage.getItem('COMMENT_LIKE_HISTORY');
  if (commentLikeHistory)
    store.commit('comment/SET_LIKEHISTORY', commentLikeHistory);

  const articleLikeHistory = localStorage.getItem('ARTICLE_LIKE_HISTORY');
  if (articleLikeHistory)
    store.commit('article/SET_LIKEHISTORY', articleLikeHistory);
};
